let MS = require('./ms.js')
const request = require('./request.js')
const Error = require('./error')
const storage = require('./storage.js')

const {
    isObject,
    isString,
    isNumber,
    isUndefined,
    isBoolean,
    isArray
} = require('./dataType.js')

const member = class member {

    get(id) {
        let params = {
            id: id
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.MEMBER.GET_MEMBER.url,
                MS._config.parameters.MEMBER.GET_MEMBER.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    loadOpenCardRecord(options) {
        let params = {
            pageNum: 1,
            pageSize: 10
        }
        if(!isUndefined(options)) {
            if(!isUndefined(options.memberId) && isString(options.memberId)) {
                params.memberId = options.memberId;
            }
            if(!isUndefined(options.pageNum) && isNumber(options.pageNum)) {
                params.pageNum = options.pageNum;
            }
            if(!isUndefined(options.pageSize) && isNumber(options.pageSize)) {
                params.pageSize = options.pageSize;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.MEMBER.LOAD_OPEN_CARD_RECORD.url,
                MS._config.parameters.MEMBER.LOAD_OPEN_CARD_RECORD.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    loadBookingShips(options) {
        let params = {
            pageNum: 1,
            pageSize: 10
        }
        if(!isUndefined(options)) {
            if(!isUndefined(options.memberId) && isString(options.memberId)) {
                params.memberId = options.memberId;
            }
            if(!isUndefined(options.pageNum) && isNumber(options.pageNum)) {
                params.pageNum = options.pageNum;
            }
            if(!isUndefined(options.pageSize) && isNumber(options.pageSize)) {
                params.pageSize = options.pageSize;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.MEMBER.LOAD_BOOKING_SHIPS.url,
                MS._config.parameters.MEMBER.LOAD_BOOKING_SHIPS.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    loadConsume(options) {
        let params = {
            pageNum: 1,
            pageSize: 10
        }
        if(!isUndefined(options)) {
            if(!isUndefined(options.memberId) && isString(options.memberId)) {
                params.memberId = options.memberId;
            }
            if(!isUndefined(options.pageNum) && isNumber(options.pageNum)) {
                params.pageNum = options.pageNum;
            }
            if(!isUndefined(options.pageSize) && isNumber(options.pageSize)) {
                params.pageSize = options.pageSize;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.MEMBER.LOAD_CONSUME.url,
                MS._config.parameters.MEMBER.LOAD_CONSUME.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = member